package com.ysxsoft.wdg.ui.activity.my;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.classic.common.MultipleStatusView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.response.XieYiResponse;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.net.UrlHost;
import com.ysxsoft.wdg.util.JsonUtils;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.WebViewUtils;
import com.ysxsoft.wdg.util.statusbar.StatusBarUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * create by Sincerly on 2018/12/7 0007
 **/
public class XieYiActivity extends BaseActivity {
    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_finish)
    ImageView titleFinish;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_iv_r)
    ImageView titleIvR;
    @BindView(R.id.title_tv_r)
    TextView titleTvR;
    @BindView(R.id.webView)
    WebView webView;
    @BindView(R.id.multStatusView)
    MultipleStatusView multStatusView;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_xie_yi;
    }

    @Override
    protected void initData() {
        titleContent.setText("商家入驻协议");
        initStatusBar(topView, true);
        WebViewUtils.init(webView);
        getXieYi();
    }

    @Override
    protected void setListener() {

    }

    @OnClick(R.id.title_finish)
    public void onViewClicked() {
        finish();
    }

    private void getXieYi() {
        multStatusView.showLoading();
        OkHttpUtils.post()
                .url(UrlHost.XIE_YI)
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                if (!call.isCanceled()) {
                    multStatusView.showContent();
                }
            }

            @Override
            public void onResponse(String response, int id) {
                multStatusView.showContent();
                if (response != null) {
                    XieYiResponse xieYiResponse = JsonUtils.parseByGson(response, XieYiResponse.class);
                    if (xieYiResponse != null) {
                        if (CallbackCode.SUCCESS.equals(xieYiResponse.getCode())) {
//                            ToastUtils.showToast(xieYiResponse.getMs());
                            String data = xieYiResponse.getData();
                            WebViewUtils.setData(webView, data);
                        } else {
                            ToastUtils.showToast(xieYiResponse.getMs());
                        }
                    } else {
                        ToastUtils.showToast("请求失败！");
                    }
                } else {
                }
            }
        });
    }
}
